<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <style type="text/css">
        .textbox.textbox-focused .textbox-addon,
        .textbox.textbox-focused .textbox-text{
            background: #eee!important;
        }
    </style>
    <script type="text/javascript">
        var id = "${id}";
        submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {
                var obj=sy.serializeObject($('form'));
                var url=sy.contextPath + '/chemicalType/save';
                var data = [];
                    if($("#title1").textbox('getValue').length != 0){
                        var title = $("#title1").textbox('getValue');
                        var content = editor1.getHtml();
                        var json = {title:title,content:content};
                        data.push(json);
                    }
                    if($("#title2").textbox('getValue').length != 0){
                        var title = $("#title2").textbox('getValue');
                        var content = editor2.getHtml();
                        var json = {title:title,content:content};
                        data.push(json);
                    }
                    if($("#title3").textbox('getValue').length != 0){
                        var title = $("#title3").textbox('getValue');
                        var content = editor3.getHtml();
                        var json = {title:title,content:content};
                        data.push(json);
                    }

                obj.rangUpInfo = sy.jsonToString(data);
                obj.id = id;
                parent.$.messager.confirm('询问', '确定保存？', function(r) {
                    if (r) {
                        $.post(url, obj, function(result) {
                            if (result.code == 0) {
                                parent.$.messager.i('保存成功');
                                $grid.datagrid('reload');
                                $dialog.dialog('destroy');
                            } else {
                                $pjq.messager.e('保存失败,'+result.msg);
                            }
                        }, 'json');
                    }
                });
            }
        };

        $(function() {
            editor1 = new HtmlEditor('#content1');
            editor2 = new HtmlEditor('#content2');
            editor3 = new HtmlEditor('#content3');
            if(id != ''){
                $.post(sy.contextPath + '/chemicalType/findById', {
                    id : id,
                }, function(result) {
                    if (id != '') {
                        $.post(sy.contextPath + '/chemicalType/findById', {
                            id : id
                        }, function(result) {
                            if(result.rangUpInfo != ''){
                                var data = sy.stringToJSON(result.rangUpInfo);
                                if(data.length == 2){
                                    $('#title1').textbox('setValue',data[0].title);
                                    editor1.setHtml(data[0].content);
                                    $('#title2').textbox('setValue',data[1].title);
                                    editor2.setHtml(data[1].content);
                                }
                                if(data.length == 3){
                                    $('#title1').textbox('setValue',data[0].title);
                                    editor1.setHtml(data[0].content);
                                    $('#title2').textbox('setValue',data[1].title);
                                    editor2.setHtml(data[1].content);
                                    $('#title3').textbox('setValue',data[2].title);
                                    editor3.setHtml(data[2].content);
                                }
                            }
                            parent.$.messager.progress('close');
                        }, 'json');

                    }
                })
            }
        });

    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">
            <tr >
                <th style="width: 100px">结果分析</th>
                <td colspan="3">
                    <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable" >
                        <tr>
                        <th style="width:30px;">标题</th>
                            <td>
                                <input id="title1" name="title1" class="easyui-textbox" data-options="validType:[length[0,300]],multiline : true" missingMessage="请输入标题"/>
                            </td>
                        </tr>
                        <tr>
                        <th style="width:30px;">内容</th>
                            <td>
                                <textarea id="content1" style="width:98%;height: 200px"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <th style="width:30px;">标题</th>
                            <td>
                                <input id="title2" name="title2" class="easyui-textbox" data-options="validType:[length[0,300]],multiline : true" missingMessage="请输入标题"/>
                            </td>
                        </tr>
                        <tr>
                            <th style="width:30px;">内容</th>
                            <td>
                                <textarea id="content2" style="width:98%;height: 200px"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <th style="width:30px;">标题</th>
                            <td>
                                <input id="title3" name="title3" class="easyui-textbox" data-options="validType:[length[0,300]],multiline : true" missingMessage="请输入标题"/>
                            </td>
                        </tr>
                        <tr>
                            <th style="width:30px;">内容</th>
                            <td>
                                <textarea id="content3" style="width:98%;height: 200px"></textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>
</body>
</html>